<?php
// 新增商品信息
require $this->website['path']['action'] . '/admin/isedit.php';

$json = array('status' => 'error', 'msg' => '', 'data' => []);

$data = fn_post('data');

$data = json_decode($data, 1);
//data['product']
//data['image']
 
//data['detail']
 

if (!count($data['product'])) {
	$json['msg'] = '请添加剂基本信息 ';
} else {
	// product
	$field = array_keys($data['product']);
	$value = array_values($data['product']);
	$field[] = 'createtime';
	$value[] = $_SERVER['REQUEST_TIME'];

	// $json['data'] = $field;
	// $this->json_encode($json);

	$id = $this->website['class']['db']
		->table('product')
		->field($field)
		->value($value)
		->insert();

	if (!$id) {
		$json['msg'] = '保存商品数据错误';
		$this->json_encode($json);
	}
	// image
	if (count($data['image'])) {
		foreach ($data['image'] as $v) {
			$this->website['class']['db']
				->table('product_image')
				->field('pid', 'image')
				->value($id, $v)
				->insert();
		}
	}
	// detail
	if (count($data['detail'])) {
		foreach ($data['detail'] as $v) {
			$this->website['class']['db']
				->table('product_detail')
				->field('pid', 'image')
				->value($id, $v)
				->insert();
		}
	}
 
 

 

	$json['status'] = 'ok';
	$json['msg'] = '新增商品成功.';
}
$json['data'] = $data;
$this->json_encode($json);
